<template>
    <div>
        <h2>list2添加页面</h2>
        <p>姓名：<input type="text" v-model="name"></p>
        <p>图片：<input type="file" @change="get_file($event)"></p>
        <p>分类：
            <select v-model="cates">
                <option v-for="(i,d) in cate" :value="i.id" :key="d">{{i.name}}</option>
           </select>
        </p>
        <p><input type="button" value="添加英雄" @click="addlistt()"></p>
    </div>
</template>

<script>
import axios from "axios"
import {get_one} from "../axios_api/api.js"
export default {
    name:"addlistt",
    data() {
        return {
            name:"",
            pic:"",
            cate:"",
            cates:""
        }
    },
    methods:{
        get_file(event){
            this.file = event.target.files[0]
        },
        get_cate(){
            get_one().then(res=>{
                console.log(res)
                this.cate = res.data
            })
        },
       addlistt(){
           let formdata = new FormData()
           formdata.append("name",this.name)
           formdata.append("pic",this.file)
           formdata.append("cate",this.cates)
           axios({
                url:'http://127.0.0.1:8000/app02/listtow/',
                method:'post',
                data:formdata
            }).then(res=>{
                console.log(res.data)
            })
        },
    },
    created(){
        this.get_cate()
    }
    
}
</script>

<style>

</style>
